Forum:Code Review:Extension:ImageSizeInfoFunctions
This is a tentative fix for mw:Extension:ImageSizeInfoFunctions over at mediawiki.org. The extension does not work in its current form and the maintainer and all other contributors appear to be gone. That's why I'm posting it here. There's no one at mediawiki.org to read it. This extension is used heavily on the Fallout wiki and at least 50 % of their pages are broken right now. Having installed mediawiki 1.21 on my own machine I can confirm that the extension in its current form throws lots of exceptions. This my attempt of a rewrite. It works fine on my own machine (and under mediawiki 1.21), but that doesn't mean it's fit to be posted to mediawiki.org yet. I know next to nothing about the mediaWiki codebase, so there are probably some glaring errors. Take a look, please! ImageSizeInfoFunctions.php if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); } $wgExtensionCredits'parserhook'[] = array( 'name' => 'ImageSizeInfoFunctions', 'version' => '1.1', 'url' => 'http://www.mediawiki.org/wiki/Extension:ImageSizeInfoFunctions', 'author' => 'Peter Coester', 'description' => 'Enhance parser with image size info functions', ); $wgExtensionMessagesFiles'ImageSizeInfoFunctions' = dirname( __FILE__ ) . '/ImageSizeInfoFunctions.i18n.php'; $wgHooks'ParserFirstCallInit'[] = function ( $parser ) { $parser->setFunctionHook( 'imgw', function ( $parser, $image = '' ) { $file = wfFindFile( Title::newFromText( $image, NS_IMAGE ) ); $width = (is_object($file) && $file->exists()) ? $file->getWidth() : 0; return $width; } ); $parser->setFunctionHook( 'imgh', function ( $parser, $image = '' ) { $file = wfFindFile( Title::newFromText( $image, NS_IMAGE ) ); $height = (is_object($file) && $file->exists()) ? $file->getHeight() : 0; return $height; } ); return true; }; ImageSizeInfoFunctions.i18n.php (The original code also adds a message, but it doesn't appear to use it at all, so I dropped it.) $magicWords = array(); $magicWords'en' = array( 'imgw' => array( 0, 'imgw' ), 'imgh' => array( 0, 'imgh' ) ); :I'd submit this as a pull request at http://www.github.com/Wikia/app/pulls --[[User:Kangaroopower|'Kangaroopowah']] ([[User Talk:Kangaroopower|'Talk']]) 03:12, May 28, 2013 (UTC) ::Thanks! I did not know I could submit things there. But don't you think I should submit it to MediaWiki first? I'm a little fuzzy on the politics. Submitting it directly to Wikia would probably be faster though, wouldn't it? Hm... -- :::This is a core extension, so you should ask for dev access at MediaWiki and use their Git repo and Gerrit to merge the fix. Then, you should S:C in to Staff to merge the updates.TK-999 (talk) 13:56, May 28, 2013 (UTC) ::::Thanks! I'll do that. What about the code then? Does it look okay to you? Or should I just submit it and trust in wikiMedia's review process? I'm asking because none of the extension's previous contributors seem to be around anymore. -- I think you should not declare the function when you register the hook; it expects a string. So this should be better—this is what I saw every extension do: $wgHooks'ParserFirstCallInit'[] = 'efImageSizeInfoFunctions'; function efImageSizeInfoFunctions( Parser $parser ) { // Awesome function. } And it's very fine otherwise, at least to me. :)TK-999 (talk) 15:47, May 28, 2013 (UTC) :Well, that bit should be fine actually. (Unless it violates a mediaWiki coding convention of course...) But PHP doesn't care how you specify the function. A function literal will do just as well as a function name in string form or a method name in array form. As long as it's callable PHP does fine. --